use axum::{
    routing::{get, post},
    Router,
};
use log::info;

use crate::statics::SERVER_CONFIG;

mod api;
#[cfg(feature = "use_cache")]
mod cache;
mod config;
mod server;
mod statics;

#[tokio::main]
async fn main() {
    env_logger::builder()
        .filter_level(log::LevelFilter::Info)
        .try_init()
        .unwrap();
    let app = Router::new()
        .route(
            "/api/data",
            post(server::data::post_data).get(server::data::post_data),
        )
        .fallback(server::e404::e404)
        .route("/test/", get(test));
    let addr = &SERVER_CONFIG.addr;
    info!("Now starting server.");
    let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

async fn test() -> &'static str {
    "Hello, World!"
}
